package com.qjj.studydainty.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;


import com.google.android.material.tabs.TabLayout;
import com.qjj.studydainty.R;
import com.qjj.studydainty.adapter.RecorderFragmentPagerAdapter;
import com.qjj.studydainty.entity.MyApplication;
import com.qjj.studydainty.fragment.HistoryFragment;
import com.qjj.studydainty.fragment.MarkerFragment;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class RecorderActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme();
        setContentView(R.layout.activity_recorder);
        initFragment();
    }

    private void setTheme() {
        if (MyApplication.SHOW_THEME_FLAG == MyApplication.SHOW_WHITE_THEME_FLAG) {
            setTheme(R.style.DayTheme);
        } else if (MyApplication.SHOW_THEME_FLAG == MyApplication.SHOW_BLACK_THEME_FLAG) {
            setTheme(R.style.NightTheme);
        }
    }

    //初始化碎片管理器和默认碎片
    private void initFragment() {

        ViewPager liveViewPager = findViewById(R.id.view_pager);
        List<Fragment> liveFragmentList = new ArrayList<>();

        liveFragmentList.add(new MarkerFragment());
        liveFragmentList.add(new HistoryFragment());
        RecorderFragmentPagerAdapter recorderFragmentPagerAdapter = new RecorderFragmentPagerAdapter(getSupportFragmentManager(), liveFragmentList);
        liveViewPager.setAdapter(recorderFragmentPagerAdapter);

        TabLayout mTab = findViewById(R.id.live_main_tab);
        //设置tab的模式
        //mTab.setTabMode(TabLayout.MODE_FIXED);不可滚动的tab
        //app:tabMode="scrollable"可以滑动的tab

        //把TabLayout和ViewPager关联起来
        mTab.setupWithViewPager(liveViewPager);

        Objects.requireNonNull(mTab.getTabAt(0)).setText("书签");
        Objects.requireNonNull(mTab.getTabAt(1)).setText("历史");

    }
}
